from django.db import models


# Create your models here.
# 学院表
class Department(models.Model):
    d_id = models.AutoField(primary_key=True)
    d_name = models.CharField(max_length=10, unique=True)

    def __str_(self):
        return f'd_id={self.d_id},d_name={self.d_name}'


# 学生表
class Student(models.Model):
    s_id = models.AutoField(primary_key=True)
    s_name = models.CharField(max_length=10)
    # 一对多关系
    d_id = models.ForeignKey('Department', on_delete=models.SET_NULL, null=True)

    def __str__(self):
        return f's_id={self.s_id},s_name={self.s_name}'


# 学生详情
class Stu_detail(models.Model):
    sd_id = models.AutoField(primary_key=True)
    sd_sex = models.BooleanField(default=1)
    sd_age = models.IntegerField()
    intro = models.TextField(null=True)
    # 一对一关系
    s_id = models.OneToOneField('Student', on_delete=models.CASCADE, unique=True)

    def __str__(self):
        return f'sd_id={self.sd_id},sd_sex={self.sd_sex},sd_age={self.sd_age},sd_Inrto={self.intro}'


class Course(models.Model):
    c_id = models.AutoField(primary_key=True)
    c_name = models.CharField(max_length=10,unique=True)
    # 多对多关系
    c_id = models.ManyToManyField('Student')

    def __str__(self):
        return f'c_id={self.c_id},c_name={self.c_name}'
